package map;
/**
 * -------------------------------------> Sorting <----------------------------------------

  We can sort the elements of:

   String objects
   Wrapper class objects
   User-defined class objects
   Collections class provides static methods for sorting the elements of collection.If collection elements 
   are of Set type, we can use TreeSet.But We cannot sort the elements of List.Collections class provides 
   methods for sorting the elements of List type elements.
   
   Method of Collections class for sorting List elements

   public void sort(List list): is used to sort the elements of List.List elements must be of Comparable type.
   
   
   Note: String class and Wrapper classes implements the Comparable interface.So if you store the objects
         of string or wrapper classes, it will be Comparable.


 */
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;

public class Sorting {
public static void main(String[] args) {
	//Example of Sorting the elements of List that contains string objects
	
	/**
	LinkedList<String> ll = new LinkedList<>();
	ll.add("y");
	ll.add("z");
	ll.add("a");
	ll.add("o");
	Collections.sort(ll);
	Iterator<String> itr = ll.iterator(); 
	while (itr.hasNext()){
		System.out.println(itr.next());
	}*/
	
    // Example of Sorting the elements of List that contains the wrapper class objects.
	
	ArrayList ll = new ArrayList();
	ll.add(Integer.valueOf(15));
	ll.add(Integer.valueOf(12));
	ll.add(Integer.valueOf(11));
	ll.add(13); //internally will be converted into objects as Integer.valueOf(13)
	Collections.sort(ll);
	Iterator itr = ll.iterator();
	while(itr.hasNext()){
		System.out.println(itr.next());
	}
}
}
